import "./init/bmob.init.js"

const queryVisit = Bmob.Query('web_visit');

/**
 * 保存用户信息至Bmob
 */
export function saveWebVisit(res) {
    queryVisit.set("ip", res.ip || "")
    queryVisit.set("city", res.city || "")
    queryVisit.set("address", res.address || "")

    // 通用参数
    queryVisit.set("error", res.error || "")
    queryVisit.set("url", window.location.href)
    queryVisit.set("ua", navigator.userAgent)
    queryVisit.set("referrer", document.referrer)
    queryVisit.set("visitorId", window.visitorId || "")

    queryVisit.save().then(res => {
        console.log("保存结果", res)
        queryVisit.get(res.objectId).then(res => {
            console.log("查询结果", res)
        }).catch(err => {
            console.log(err)
        })
    }).catch(err => {
        console.log(err)
    })
}
